**** Stefan Mueller, Samuel Brazys, Alexander Dukalsksi

**** University College Dublin
**** 21-12-2023
  
* Set object "data" to my data directory location
 
global data="C:\Users\sabra\My Drive\China_Media\Data\"

global results="C:\Results\ChinaCOVID"

* Change working directory to "$data"

cd "$data"

* Set more off (for page scrolling)
 
set more off
 
set matsize 11000

* Load Data
 
import delimited "$data\data_news_covid_weeks_21_12_23.csv", clear
* Generate country code

 encode iso3, gen(ccode)

 
* Make sure country filled in for all observations
 
bys iso3: egen country2=mode(country)

drop country
 
rename country2 country

*Generate no-gap week variable
 
gen week2=substr(week_year,1,2)
 
replace week2=subinstr(week2, "_","",.)

destring week2, replace

replace week2=week2+52 if year==2021
 
** Generate STATA Day variable for merge
 
generate day=date( date_week_news_start, "DMY")
 
*replace negative case and death data with missing
 
replace deaths_weekly=. if cases_weekly<0
 
replace cases_weekly=. if cases_weekly<0
 
replace deaths_weekly_per_million=. if cases_weekly_per_million<0

replace cases_weekly_per_million=. if cases_weekly_per_million<0

* set tsset
 
tsset ccode week2

** generate difference measures
 
sort ccode week2 

** Generate standardized measure of score (mean 0, sd 1)
 
*** OMIT to run all languages, all articles - include to run permuatations below
 
* drop mean_score_sameweek

** No Mask Diplomacy articles (all languages)

*rename mean_score_sameweek_no_maskdip mean_score_sameweek
 
** For English Only
 
* rename mean_score_sameweek_no_translate mean_score_sameweek
 
** English only with no mask diplomacy articles
 
*rename mean_score_nomask_english mean_score_sameweek
 
** Generate standardized measure of score (mean 0, sd 1)
 
bys ccode: egen mean_score_ccode=mean(mean_score_sameweek)
 
bys ccode: egen sd_mean_score_ccode=sd(mean_score_sameweek)
 
gen std_mean_score=(mean_score_sameweek- mean_score_ccode)/ sd_mean_score_ccode

** generate country-period (4 week) fixed effects

gen week_4=week2/4

replace week_4=int(week_4)

egen xx=group(ccode week_4)

quietly tab xx, gen(cdt)

tsset ccode week2

** Add BRI info

merge m:m iso3 using "C:\Users\sabra\My Drive\China_Media\Data\BRI.dta"

drop if _m==2

drop _m

*** Add other BRIs

replace BRI=0 if BRI==.

replace BRI=1 if country=="Algeria"
 
replace BRI=1 if country=="Austria"

replace BRI=1 if country=="Barbados"

replace BRI=1 if country=="Bosnia & Herzegovina"

replace BRI=1 if country=="Congo - Brazzaville"

replace BRI=1 if country=="Georgia"

replace BRI=1 if country=="Hungary"

replace BRI=1 if country=="Liberia"

replace BRI=1 if country=="Lithuania"

replace BRI=1 if country=="Madagascar"

replace BRI=1 if country=="Maldives"

replace BRI=1 if country=="Mali"

replace BRI=1 if country=="Moldova"

replace BRI=1 if country=="Oman"

replace BRI=1 if country=="Romania"

replace BRI=1 if country=="Serbia"

replace BRI=1 if country=="Seychelles"

replace BRI=1 if country=="Tajikistan"

replace BRI=1 if country=="Tunisia"

*drop China

drop if iso3=="CHN"

tsset ccode week2

tsfill, full

bys ccode: egen fc=mode(country)

replace country=fc if country==""

*** Mask Diplomacy
 
* Include all mask diplomacy activities
 
joinby country week2 using "C:\Users\sabra\My Drive\China_Media\Data\mask_diplomacy_thin_deduplicated_UPDATE_DAILY.dta", unm(both)

*Include only non-RMC (Remote Medical Consultation

*joinby country week2 using "C:\Users\sabra\My Drive\China_Media\Data\mask_diplomacy_thin_deduplicated_UPDATE_DAILY_no_RMC.dta", unm(both)


**** Mask diplomacy heterogeneity - treatment if first instance of TYPE of mask diplomacy

gen mask_diplomacy=1 if _m==3

drop if _m==2

drop _m

replace mask_diplomacy=0 if mask_diplomacy==.

gen Mask=mask_diplomacy

*** Set up for diff-in-diff

sort ccode week2

bys ccode: egen min_week_mask=min(week2) if mask_diplomacy==1

bys ccode: egen treated=max(mask_diplomacy)

egen ccode_num=group(ccode)

*** Set up rolling diff-diff (untreated until 2 weeks before first mask diplomacy)

drop if year==2021

bys ccode: egen min_week_t=min(min_week_mask)

duplicates drop ccode week2, force

tsset ccode_num week2

tsfill, full
 
keep week2 min_week_t treated std_mean_score ccode country ccode_num cases_weekly_per_million deaths_weekly_per_million iso3 BRI vdem_above_median_censor_interne vdem_above_median_liberal_democr vdem_above_median_electoral_demo export_chi_above_median un_agree_above_median mean_score_sameweek

bys ccode_num: egen min_t=max(min_week_t)

replace deaths=0 if deaths==.

replace cases=0 if cases==.

bys ccode_num: egen case_mean=mean(cases)

bys ccode_num: egen death_mean=mean(deaths)

bys ccode_num: egen iso33=mode(iso3)

replace iso3=iso33

drop iso33

rename cases_ cases

rename deaths_ deaths

replace min_week_t=0 if min_week_t==.

replace min_t=0 if min_t==.

drop if week>26

*Generate split samples for R diff diff - All Articles/All Languages/All Mask Diplomacy Build

preserve
keep if BRI==0
export delimited using "did_r_nonBRI", replace
restore

preserve
keep if BRI==1
export delimited using "did_r_BRI", replace
restore

preserve
keep if export_china_above_median==1
export delimited using "did_r_export", replace
restore

preserve
keep if export_china_above_median==0
export delimited using "did_r_nonexport", replace
restore

preserve
keep if vdem_above_median_electoral_demo==1
export delimited using "did_r_edem", replace
restore

preserve
keep if vdem_above_median_electoral_demo==0
export delimited using "did_r_noedem", replace
restore

preserve
keep if vdem_above_median_censor_interne==1
export delimited using "did_r_censor", replace
restore

preserve
keep if vdem_above_median_censor_interne==0
export delimited using "did_r_nocensor", replace
restore

preserve
keep if un_agree_above_median==1
export delimited using "did_r_unga", replace
restore

preserve
keep if un_agree_above_median==0
export delimited using "did_r_nounga", replace
restore

export delimited using "did_r_FULL", replace

*Split samples for DiD using ENGLISH ONLY - All Articles/English Only/All Mask Diplomacy Build

preserve
keep if BRI==0
export delimited using "did_r_nonBRI_E", replace
restore

preserve
keep if BRI==1
export delimited using "did_r_BRI_E", replace
restore

preserve
keep if export_china_above_median==1
export delimited using "did_r_export_E", replace
restore

preserve
keep if export_china_above_median==0
export delimited using "did_r_nonexport_E", replace
restore

preserve
keep if vdem_above_median_electoral_demo==1
export delimited using "did_r_edem_E", replace
restore

preserve
keep if vdem_above_median_electoral_demo==0
export delimited using "did_r_noedem_E", replace
restore

preserve
keep if vdem_above_median_censor_interne==1
export delimited using "did_r_censor_E", replace
restore

preserve
keep if vdem_above_median_censor_interne==0
export delimited using "did_r_nocensor_E", replace
restore

preserve
keep if un_agree_above_median==1
export delimited using "did_r_unga_E", replace
restore

preserve
keep if un_agree_above_median==0
export delimited using "did_r_nounga_E", replace
restore

export delimited using "did_r_ENGLISH", replace

*Generate split samples for R diff diff NO RMC - All Articles/All Languagues/No Remote Medical Consulations Build

preserve
keep if BRI==0
export delimited using "did_r_nonBRI_nrmc", replace
restore

preserve
keep if BRI==1
export delimited using "did_r_BRI_nrmc", replace
restore

preserve
keep if export_china_above_median==1
export delimited using "did_r_export_nrmc", replace
restore

preserve
keep if export_china_above_median==0
export delimited using "did_r_nonexport_nrmc", replace
restore

preserve
keep if vdem_above_median_electoral_demo==1
export delimited using "did_r_edem_nrmc", replace
restore

preserve
keep if vdem_above_median_electoral_demo==0
export delimited using "did_r_noedem_nrmc", replace
restore

preserve
keep if vdem_above_median_censor_interne==1
export delimited using "did_r_censor_nrmc", replace
restore

preserve
keep if vdem_above_median_censor_interne==0
export delimited using "did_r_nocensor_nrmc", replace
restore

preserve
keep if un_agree_above_median==1
export delimited using "did_r_unga_nrmc", replace
restore

preserve
keep if un_agree_above_median==0
export delimited using "did_r_nounga_nrmc", replace
restore

export delimited using "did_r_noRMC", replace

*Generate split samples for R diff diff NO RMC ENGLISH - All Articles/English Only/No Remote Medical Consulations Build

preserve
keep if BRI==0
export delimited using "did_r_nonBRI_nrmc_E", replace
restore

preserve
keep if BRI==1
export delimited using "did_r_BRI_nrmc_E", replace
restore

preserve
keep if export_china_above_median==1
export delimited using "did_r_export_nrmc_E", replace
restore

preserve
keep if export_china_above_median==0
export delimited using "did_r_nonexport_nrmc_E", replace
restore

preserve
keep if vdem_above_median_electoral_demo==1
export delimited using "did_r_edem_nrmc_E", replace
restore

preserve
keep if vdem_above_median_electoral_demo==0
export delimited using "did_r_noedem_nrmc_E", replace
restore

preserve
keep if vdem_above_median_censor_interne==1
export delimited using "did_r_censor_nrmc_E", replace
restore

preserve
keep if vdem_above_median_censor_interne==0
export delimited using "did_r_nocensor_nrmc_E", replace
restore

preserve
keep if un_agree_above_median==1
export delimited using "did_r_unga_nrmc_E", replace
restore

preserve
keep if un_agree_above_median==0
export delimited using "did_r_nounga_nrmc_E", replace
restore

export delimited using "did_r_noRMC_ENGLISH", replace

***

*Generate Other Main Output Files

** No Mask Diplomacy Artices/All Languages/All Mask Diplomacy Types Build
export delimited using "did_r_nomask", replace

** No Mask Diplomacy Artices/English Only/All Mask Diplomacy Types Build
export delimited using "did_r_nomask_ENGLISH", replace

***********************************************************************************************
*********************************** DEATH PEAKS BUILD *****************************************
***********************************************************************************************

clear all

* Set object "data" to my data directory location
 
global data="C:\Users\sabra\My Drive\China_Media\Data\"

global results="C:\Results\ChinaCOVID"

* Change working directory to "$data"

cd "$data"

* Set more off (for page scrolling)
 
set more off
 
set matsize 11000

* Load Data
 
import delimited "$data\data_news_covid_weeks_21_12_23.csv", clear

* Generate country code
encode iso3, gen(ccode)

*Make sure country filled in for all observations
bys iso3: egen country2=mode(country)
drop country
rename country2 country

*Generate no-gap week variable
gen week2=substr(week_year,1,2)
replace week2=subinstr(week2, "_","",.)
destring week2, replace
replace week2=week2+52 if year==2021

** Generate STATA Day variable for merge
generate day=date( date_week_news_start, "DMY")

*replace negative case and death data with missing
replace deaths_weekly=. if cases_weekly<0
replace cases_weekly=. if cases_weekly<0
replace deaths_weekly_per_million=. if cases_weekly_per_million<0
replace cases_weekly_per_million=. if cases_weekly_per_million<0


* set tsset
tsset ccode week2


** generate difference measures
sort ccode week2 

** Replace with only english language articles

drop mean_score_sameweek

rename mean_score_sameweek_no_translate mean_score_sameweek

** Generate standardized measure of score (mean 0, sd 1)
bys ccode: egen mean_score_ccode=mean(mean_score_sameweek)
bys ccode: egen sd_mean_score_ccode=sd(mean_score_sameweek)
gen std_mean_score=(mean_score_sameweek- mean_score_ccode)/ sd_mean_score_ccode

** generate country-period (4 week) fixed effects
gen week_4=week2/4
replace week_4=int(week_4)
egen xx=group(ccode week_4)
quietly tab xx, gen(cdt)

tsset ccode week2

** Add BRI info
merge m:m iso3 using "$data\BRI.dta"
drop if _m==2
drop _m

*** Add other BRIs
replace BRI=0 if BRI==.
replace BRI=1 if country=="Algeria"
replace BRI=1 if country=="Austria"
replace BRI=1 if country=="Barbados"
replace BRI=1 if country=="Bosnia & Herzegovina"
replace BRI=1 if country=="Congo - Brazzaville"
replace BRI=1 if country=="Georgia"
replace BRI=1 if country=="Hungary"
replace BRI=1 if country=="Liberia"
replace BRI=1 if country=="Lithuania"
replace BRI=1 if country=="Madagascar"
replace BRI=1 if country=="Maldives"
replace BRI=1 if country=="Mali"
replace BRI=1 if country=="Moldova"
replace BRI=1 if country=="Oman"
replace BRI=1 if country=="Romania"
replace BRI=1 if country=="Serbia"
replace BRI=1 if country=="Seychelles"
replace BRI=1 if country=="Tajikistan"
replace BRI=1 if country=="Tunisia"

*drop China
drop if iso3=="CHN"

*** Deaths models

gen Deaths=deaths_weekly_per_million
tsset ccode week2

**** Death models with Peak Dummy *******

*Find max death week by country
bys ccode: egen max_death=max( deaths_weekly_per_million)
gen max_death_week=0
replace max_death_week=week2 if max_death==deaths_weekly_per_million
gen max_death_week_binary=0
replace max_death_week_binary=1 if max_death_week>0
gen Peak=max_death_week_binary
*replace peak only for first instance at a given death level
gen dwpm=deaths_weekly_per_million
replace Peak=0 if dwpm==l.dwpm | dwpm==l2.dwpm | dwpm==l3.dwpm | dwpm==l4.dwpm

*Generate local Peak (at least 4 weeks either direction
gen Peak_local=0
replace Peak_local=1 if dwpm>=l.dwpm & dwpm>=l2.dwpm & dwpm>=l3.dwpm & dwpm>=l4.dwpm & dwpm>=f.dwpm & dwpm>=f2.dwpm & dwpm>=f3.dwpm & dwpm>=f4.dwpm
replace Peak_local=0 if dwpm==0
replace Peak_local=0 if dwpm==l.dwpm | dwpm==l2.dwpm | dwpm==l3.dwpm | dwpm==l4.dwpm

*** Peak Histogram
hist week2 if Peak==1

*Table A.4

*** Model 1 OLS
reg std_mean_score Peak, cluster(ccode)
outreg2 using $results/RESULTS_06_05_death_peak_ALL.doc, append dec(3) ctitle(OLS) keep(Peak) title(`v') nocons  slow(100) addtext(Country NO, YES, Country-Period FE, NO, Time Trend, NO) 


*** Model 2 Regression with country fixed effects
xtreg std_mean_score Peak, fe cluster(ccode)
outreg2 using $results/RESULTS_06_05_death_peak_ALL.doc, append dec(3) ctitle(CFE) keep(Peak) title(`v') nocons  slow(100) addtext(Country FE, YES, Country-Period FE, NO, Time Trend, NO) 


*** Model 3 Regression with country fixed effects and duration trend
xtreg std_mean_score Peak week2, fe cluster(ccode)
outreg2 using $results/RESULTS_06_05_death_peak_ALL.doc, append dec(3) ctitle(Trend) keep(Peak) title(`v') nocons  slow(100) addtext(Country FE, YES, Country-Period FE, NO, Time Trend, YES) 


*** Model 4 Regression with TWFE
xtreg std_mean_score Peak i.week2, fe cluster(ccode)
outreg2 using $results/RESULTS_06_05_death_peak_ALL.doc, append dec(3) ctitle(TWFE) keep(Peak) title(`v') nocons  slow(100) addtext(Country NO, YES, Country-Period FE, NO, Time Trend, NO) 


*** Model 5 Regression with country-period fixed effects
quietly: xtreg std_mean_score Peak cdt*, cluster(ccode)
outreg2 using $results/RESULTS_06_05_death_peak_ALL.doc, append dec(3) ctitle(CPFE) keep(Peak) title(`v') nocons  slow(100) addtext(Country FE, YES, Country-Period FE, NO, Time Trend, YES, Lag Period) 

***Run country-period fixed effects Regression at all lags for FIGURE A3

local x = 0
local lag_max = 10
while `x' < `lag_max' {
gen peak=l`x'.Peak
eststo: quietly xtreg std_mean_score peak week2, fe cluster(ccode)
drop peak
local x = `x' + 1
}

local x = 1
local lag_max = 10
while `x' < `lag_max' {
gen peak=f`x'.Peak
eststo: quietly xtreg std_mean_score peak week2, fe cluster(ccode)
drop peak
local x = `x' + 1
}


esttab using "$data\Peak_Lags_Figure.csv", b(5) se(5) plain replace
